<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('客户清单列表')"/>
</head>
<body class="gray-bg">

<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <input id="deptId" name="deptId" type="hidden" th:value="${user.deptId}"/>
                    <ul>
                        <li id="dept">
                            <label>部门名称：</label>
                            <input type="text" onclick="selectDeptTree()" id="deptName" name="deptName" autocomplete="off"/>
                        </li>
                        <li id="user">
                            销售姓名：<input type="text" name="userName"/>
                        </li>
                        <li>
                            公司名称：<input type="text" name="companyName"/>
                        </li>
                        <li>
                            新老客户：
                            <select id="isNew" name="isNew">
                                <option value="">请选择</option>
                                <option value="新客户">新客户</option>
                                <option value="老客户">老客户</option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="crm:customer:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary btn-edit disabled" onclick="$.operate.edit()"
               shiro:hasPermission="crm:customer:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger btn-del btn-del disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="crm:customer:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-info" onclick="$.table.importExcel()" shiro:hasPermission="crm:customer:import">
                <i class="fa fa-download"></i> 导入
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="crm:customer:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('crm:customer:edit')}]];
    var removeFlag = [[${@permission.hasPermi('crm:customer:remove')}]];
    var prefix = ctx + "crm/customer";

    var user = [[${user}]];
    var roleKey = [[${roleKey}]];

    function checkRole(role) {
        if (role.indexOf('manager')) {
            $("#dept").show();
        } else if (role.indexOf('employee')) {
            $("#dept").hide();
            $("#user").hide();
        } else {
            $("#dept").show();
        }
    }

    $(function () {
        // 检测角色
        checkRole(roleKey);

        // 初始化表格
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            importUrl: prefix + "/importData",
            importTemplateUrl: prefix + "/importTemplate",
            modalName: "客户清单",
            search: false,
            showExport: false,
            columns: [
                {
                    checkbox: true
                },
                {
                    field: 'customerId',
                    title: '客户id',
                    visible: false
                },
                {
                    field: 'deptName',
                    title: '部门名称',
                    sortable: true
                },
                {
                    field: 'jobNumber',
                    title: '员工工号',
                    sortable: true,
                    visible: false
                },
                {
                    field: 'userName',
                    title: '销售',
                    sortable: true
                },
                {
                    field: 'industry',
                    title: '行业',
                    sortable: true
                },
                {
                    field: 'salesArea',
                    title: '销售区域',
                    sortable: true
                },
                {
                    field: 'groupName',
                    title: '集团名称',
                    sortable: true
                },
                {
                    field: 'companyName',
                    title: '公司名称',
                    sortable: true
                },
                {
                    field: 'contactUser',
                    title: '联系人',
                    sortable: true
                },
                {
                    field: 'contactPhone',
                    title: '联系电话',
                    sortable: true
                },
                {
                    field: 'isNew',
                    title: '是否新客户',
                    sortable: true
                },
                {
                    field: 'isCooperated',
                    title: '是否已合作',
                    sortable: true
                },
                {
                    field: 'advertiserName',
                    title: '平台广告主名称',
                    sortable: true
                },
                {
                    field: 'advertiserNum',
                    title: '广告主数量',
                    sortable: true
                },
                {
                    field: 'registerDate',
                    title: '注册日期',
                    sortable: true,
                    visible: false
                },
                {
                    field: 'projectLocation',
                    title: '项目地',
                    sortable: true,
                    visible: false
                },
                {
                    field: 'projectName',
                    title: '项目名称',
                    sortable: true,
                    visible: false
                },
                {
                    field: 'content',
                    title: '内容',
                    sortable: false,
                    visible: false
                },
                {
                    field: 'totalConsume',
                    title: '消耗总额(单位：元)',
                    sortable: true,
                    visible: false
                },
                {
                    field: 'totalContract',
                    title: '合同总额(单位：元)',
                    sortable: true,
                    visible: false
                },
                {
                    field: 'remark',
                    title: '备注',
                    sortable: true,
                    visible: false
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.customerId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.customerId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });
</script>
</body>
<form id="importForm" enctype="multipart/form-data" class="mt20 mb20 ml20 mr20" style="display: none;">
    <div class="col-md-12">
        <div class="col-sm-pull-12">
            <div class="input-group">
                <input id='location' class="form-control" onclick="$('#file').click();" placeholder="请选择文件">
                <label class="input-group-btn">
                    <input type="button" id="i-check" value="浏览文件" class="btn btn-primary"
                           onclick="$('#file').click();">
                </label>
            </div>
        </div>
        <input type="file" name="file" id='file' accept=".xls, .xlsx"
               onchange="$('#location').val($('#file').val());" style="display: none">

        <div class="mt10 pt5">
            <input type="checkbox" id="updateSupport" name="updateSupport" title="如果客户信息已经存在，更新这条数据。"> 是否更新已经存在的客户数据
            &nbsp; <a onclick="$.table.importTemplate()" class="btn btn-default btn-sm"><i
                class="fa fa-file-excel-o"></i> 下载模板</a>
        </div>
        <font color="red" class="pull-left mt10">
            提示：仅允许导入“xls”或“xlsx”格式文件！
        </font>
    </div>
</form>


</html>